//Samantha Midkiff
/* -----------------------------------------------------------------------
 * Include the following lines in your makefile:
 *
 * unitTest1: unitTest1.c dominion.o rngs.o
 *      gcc -o unitTest1 -g  unitTest1.c dominion.o rngs.o $(CFLAGS)
 * -----------------------------------------------------------------------
 */

#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "rngs.h"

// set NOISY_TEST to 0 to remove printfs from output
#define NOISY_TEST 1

int main() {
    int i;
    int seed = 1000;
    int numPlayer = 2;
    int maxBonus = 10;
    int p, r, handCount;
    int bonus;
    int k[10] = {adventurer, council_room, feast, gardens, mine
               , remodel, smithy, village, baron, great_hall};
    int hand[MAX_HAND];
    int new_hand[MAX_HAND]; //variable to test card shuffle
    int numDiff = 0;
    int numIdentical = 0;
    struct gameState G;
    int maxHandCount = 5;
    // arrays of all coppers, silvers, and golds
    int coppers[MAX_HAND];
    int silvers[MAX_HAND];
    int golds[MAX_HAND];
       
    for (i = 0; i < MAX_HAND; i++)
    {
        coppers[i] = copper;
        silvers[i] = silver;
        golds[i] = gold;
    }


    printf ("TESTING shuffle():\n");
    for (p = 0; p < numPlayer; p++)
    {
        for (handCount = 1; handCount <= maxHandCount; handCount++)
        {
            for (bonus = 0; bonus <= maxBonus; bonus++)
            {
#if (NOISY_TEST == 1)
                printf("Player %d played. \n", p);
#endif

                memset(&G, 23, sizeof(struct gameState));   // clear the game state
                r = initializeGame(numPlayer, k, seed, &G); // initialize a new game
                                for (int i = 0; i <= MAX_HAND; ++i)
                                        {hand[i] = G.hand[p][i];}
                                       
                                shuffle(p, &G);
                               
                                for (int i = 0; i <= MAX_HAND; ++i)
                                        {new_hand[i] = G.hand[p][i];}
                                       
                                for (int i = 0; i <= MAX_HAND; ++i)
                                        {if (hand[p] != new_hand[p])
                                                {++numDiff;}
                                         else 
                                            {numIdentical++}
                                        }
                               
                                int percentageMatch = (numDiff/(sizeof(G.hand[p]) ));
                               
                                if (percentageMatch < .15)
                       
            printf("Test failed first shuffle (%d)",i) ;
       
#if (NOISY_TEST == 1)
                printf("Player %d hand was successfully shuffled once", p);
#endif
                                shuffle(p, &G);

                                for (int i = 0; i <= MAX_HAND; ++i)
                                        {hand[i] = G.hand[p][i];}
                                       
                                shuffle(p, &G);
                               
                                for (int i = 0; i <= MAX_HAND; ++i)
                                        {new_hand[i] = G.hand[p][i];}
                                       
                                for (int i = 0; i <= MAX_HAND; ++i)
                                        {if (hand[p] != new_hand[p])
                                                {++numDiff;}
                                         else 
                                            {numIdentical++}                                        
                                        }
                               
                                percentageMatch = (numDiff/(sizeof(G.hand[p])));
                               
                                if (percentageMatch < .15)
                                printf("Test failed second shuffle (%d)",i) ;
 
#if (NOISY_TEST == 1)
                printf("Player %d hand was successfully shuffled twice", p);
#endif
                }
     
    }
    printf("Shuffle tests passed!\n");
}

    return 0;
}

